import 'dart:io';

import 'package:common/network/http/http.dart';
import 'package:common/ui/pop.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';

import 'generated/l10n.dart';
import 'route.dart';

void setStatusBar() {
  // 透明状态栏
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

Widget appBuilder(BuildContext context, Widget? child) {
  return PopHeler.appBuilder(child);
}

Future<void> beforeRunApp() async {
  WidgetsFlutterBinding.ensureInitialized();
  await HTTPUtil.instance.config();

  /* import 'package:flutter/rendering.dart';
 //文本显示
  debugPaintLayerBordersEnabled = true;
  debugPaintBaselinesEnabled = true;
  */
  // debugPaintSizeEnabled = true;
  debugPrint = (String? message, {int? wrapWidth}) {
    if (!kReleaseMode) debugPrintSynchronously(message, wrapWidth: wrapWidth);
  };
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    setStatusBar();
    return GetMaterialApp(
      localizationsDelegates: [
        GlobalWidgetsLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        // 使用：有context？ S.of(context).key ： S.current.key
        S.delegate,
      ],
      // 设置中文为首选项 tod o
      supportedLocales: [
        // const Locale('zh_CN', ''),
        ...S.delegate.supportedLocales
      ],
      localeListResolutionCallback: (locales, supportedLocales) {
        debugPrint('locales: ' + locales.toString());
      },

      initialRoute: RouteConfig.loginn,
      getPages: RouteConfig.getPages,
      builder: appBuilder,
    );
  }
}
